<template>
  <div>
    <PureTableBar title="任务说明" class="th100">
      <template #buttons>
        <p class="text-red-500 absolute left-[120px] leading-7 text-sm">注：双击查看详情</p>
        <el-button type="primary" :icon="useRenderIcon(AddFill)" @click="handleUpdate(undefined)">
          添加
        </el-button>
      </template>
      <template v-slot="{ size, checkList }">
        <pure-table border align-whole="center" showOverflowTooltip table-layout="auto" :loading="loading" :size="size"
          :data="dataList" :columns="columns" :checkList="checkList" :pagination="pagination"
          :paginationSmall="size === 'small' ? true : false" :header-cell-style="{
            background: 'var(--el-table-row-hover-bg-color)',
            color: 'var(--el-text-color-primary)'
          }" @size-change="handleSizeChange" @current-change="handleCurrentChange" @cell-dblclick="handleUpdate">
          <template #operation="{ row }">
            <el-button class="reset-margin" link type="primary" :size="size" :icon="useRenderIcon(EditPen)"
              @click="handleUpdate(row)">
              修改
            </el-button>
            <el-button class="reset-margin" link type="danger" :size="size" :icon="useRenderIcon(Delete)"
              @click="handleDelete(row)">
              删除
            </el-button>
            <!-- <el-popconfirm title="是否确认删除?" @confirm="handleDelete(row)">
              <template #reference>
                <el-button class="reset-margin" link type="danger" :size="size" :icon="useRenderIcon(Delete)">
                  删除
                </el-button>
              </template>
            </el-popconfirm> -->
          </template>
        </pure-table>
      </template>
    </PureTableBar>
    <el-dialog top="5vh" @close="HideVisible(subcheck)" v-model="updatePanelVisible" :title="VisibleTitle + '任务说明'"
      width="55%" center :close-on-click-modal="false">
      <el-scrollbar height="600px">
        <el-form :model="updateFrom" :rules="rules" ref="subcheck" label-width="120px">
          <el-form-item label="菜单名称" prop="menuName">
            <el-select style="width: 200px" placeholder="请选择" filterable clearable value-key="displayName"
              v-model="updateFrom.menuName" :disabled="MenuNameDisa">
              <el-option v-for="item in ListFroms.menuList" :key="item.id" :label="item.displayName" :value="item" />
            </el-select>
          </el-form-item>
          <el-form-item label="答案类型" prop="answerType">
            <el-select style="width: 200px" placeholder="请选择" clearable value-key="displayName"
              v-model="updateFrom.answerType">
              <el-option v-for="item in ListFroms.answerType" :key="item.id" :label="item.displayName" :value="item" />
            </el-select>
          </el-form-item>
          <el-form-item label="实验答案" prop="answerTest">
            <el-input v-model="updateFrom.answerTest" :autosize="{ minRows: 4, maxRows: 4 }" class="!max-w-[700px]"
              type="textarea" />
          </el-form-item>
          <el-form-item label="实验代码" prop="answerCode">
            <el-input v-model="updateFrom.answerCode" :autosize="{ minRows: 4, maxRows: 4 }" class="!max-w-[700px]"
              type="textarea" />
          </el-form-item>
          <el-form-item label="任务说明" prop="remark" v-if="updatePanelVisible">
            <WangEditor v-model="updateFrom.remark" :height="200" />
          </el-form-item>
        </el-form>
      </el-scrollbar>
      <template #footer>
        <span class="dialog-footer">
          <el-button type="primary" @click="SaveTopic(subcheck)">保存</el-button>
          <el-button @click="HideVisible(subcheck)">取消</el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>

<script setup lang="ts">
import { useRenderIcon } from "@/components/ReIcon/src/hooks";
import { PureTableBar } from "@/components/RePureTableBar";
import WangEditor from "@/components/wangEditor/index.vue";
import AddFill from "@iconify-icons/ri/add-circle-line";
import Delete from "@iconify-icons/ep/delete";
import EditPen from "@iconify-icons/ep/edit-pen";
import { useDescription } from "./hook";
const {
  pagination,
  subcheck,
  loading,
  dataList,
  MenuNameDisa,
  ListFroms,
  updateFrom,
  updatePanelVisible,
  VisibleTitle,
  columns,
  rules,
  handleUpdate,
  SaveTopic,
  handleDelete,
  HideVisible,
  handleSizeChange,
  handleCurrentChange
} = useDescription()
</script>

<style lang="scss" scoped>
:deep(.el-table .el-table__cell.is-center) {
  overflow: hidden;
}
</style>
